var currentUserId = "";
var currentUserName = "";
var currentCourseId = "";
var currentCourseName = "";
var currentAssignmentId = "";
var currentAssignmentName = "";
var currentActivityId = "";
var currentActivityName = "";
// 以下是图表产生
var ctimes=0;
var bctimes=0;
var score=0;
var commentType="";




$(function(){
	$.ajax({
		url:'/pad/getSessionUser',
		success:function(user){
			currentUserId = user.id;
			currentUserName = user.realname;
			$("#user").html(user.realname+' <span class="caret"></span>');
		}
	});
	allCurrentActivityView();
});



/**
 * 提交表单
 */
function submitAdviceForm(formSelecter,modalSelecter){
	$("#userIdInputId").attr("value",currentUserId)
	$("#realnameInputId").attr("value",currentUserName)
	// 异步提交表单
    $(formSelecter).ajaxSubmit({  
        type:'post',
        resetForm: true,
        success:function(data){ 
        		$(modalSelecter).modal('hide');
        		var userGiveAdviceEvent={} 
        		userGiveAdviceEvent["userId"]=currentUserId;
        		userGiveAdviceEvent["activityId"]="noActivityId";
        		userGiveAdviceEvent["object"]="btn_userAdvice";
        		userGiveAdviceEvent["action"]="用户在首页给系统提建议了";
        		 $.ajax({
        			   url: "/pad/event/saveRftWritingEvent",
        			   type: 'POST',
        			   data:userGiveAdviceEvent,
        			   async: false,
        			   dataType: "json", //返回数据格式为json
        			   success: function(data) {//请求成功完成后要执行的方法
        			   }
        		 });
        },
        error:function(msg){
        	alert(msg.statusText);
        }
    });  
}



function toDocument(){
	var rftWritingEvent={} 
	rftWritingEvent["userId"]=currentUserId;
	rftWritingEvent["activityId"]="noActivityId";
	rftWritingEvent["object"]="a_toDocumentPage";
	rftWritingEvent["action"]="进入反思写作帮助文档下载页面";
	 $.ajax({
		   url: "/pad/event/saveRftWritingEvent",
		   type: 'POST',
		   data:rftWritingEvent,
		   async: false,
		   dataType: "json", //返回数据格式为json
		   success: function(data) {//请求成功完成后要执行的方法
			   window.open("/pad/document");
		   }
	 });
}

//点击编辑按钮
function clickEditBtn(assignmentId,activityId){
	var rftWritingEvent={} 
	rftWritingEvent["userId"]=currentUserId;
	rftWritingEvent["activityId"]=activityId;
	rftWritingEvent["object"]="btn_edit";
	rftWritingEvent["action"]="进入编辑页面";
	 $.ajax({
		   url: "/pad/event/saveRftWritingEvent",
		   type: 'POST',
		   data:rftWritingEvent,
		   async: false,
		   dataType: "json", //返回数据格式为json
		   success: function(data) {//请求成功完成后要执行的方法
			   window.open("/pad/edit?assignmentId="+assignmentId+"&activityId="+activityId);
		   }
	 });
}

function manageConst(courseId,courseName,assignmentId,assignmentName){
	currentCourseId = courseId?courseId:"";
	currentCourseName = courseName?courseName:"";
}
function allCurrentActivityView(){
	$('#breadcrumb').html('<li class="active">首页</li><button style="display:none" class="btn btn-info" data-toggle="modal" data-target="#createUserAdviceModal"><span class="glyphicon glyphicon-envelope"></span>&nbsp给系统提建议</button>');
	$('#toolbar').html('<button class="btn btn-info" onclick="javascript:courseListView();"><span class="glyphicon glyphicon-list-alt"></span> 我的课程列表</button><h3 class="pull-left">正在进行的活动</h3>');
	$('#visions').html('');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'activity/getAllCurrentActivity',
	    undefinedText:'',
	    striped:true,
	    toolbar:'#toolbar button',
	    toolbarAlign:'right',
	    idField:'id',
	    columns: [
	    	{field: 'activityName',title: '活动名称',width:200}, 
	    	{field: 'description',title: '活动简介'}, 
	    	{field: 'startDate',title: '开始时间',width:100}, 
	    	{field: 'endDate',title: '结束时间',width:100}, 
	    	{field: 'assignmentName',title: '所属作业',width:200}, 
	    	{field: 'courseName',title: '所属课程',width:200},
	    	{field: 'op',title: '操作',width:180,formatter:function(value,row,index){
	    		if(row.activityType=="COMMENT"){
    				return '<a href="/pad/comment.html?assignmentId='+row.assignmentId+'&activityId='+row.id+'" target="_blank" class="btn btn-info btn-xs">组内互评</a>';
    			}else if(row.activityType=="FEEDBACK"){
    				var htmlStr = '<div class="btn-group"><button class="btn btn-info btn-xs dropdown-toggle" type="button" id="dropdownMenu'+index+'" data-toggle="dropdown">组间互评<span class="caret"></span></button><ul class="dropdown-menu" style="position:relative;" role="menu" aria-labelledby="dropdownMenu'+index+'">';
    				$.ajax({
    					url:'/pad/assignment/getCommentAssignmentPad?activityId='+row.id,
	    	    		async: false,
    					success:function(data){
                           //console.log(data);
    						for(var i=0;i<data.assignmentPads.length;i++){
    							
    							if(data.assignmentPads[i]!=null)
    							htmlStr += '<li role="presentation"><a role="menuitem" tabindex="-1" target="_blank" href="/pad/feedback.html?assignmentPadId='+data.assignmentPads[i].id+'&activityId='+row.id+'">'+data.assignmentPads[i].groupName+'</a></li>';
    						}
    					}
    				});
    				htmlStr +='</ul></div> <a href="/pad/edit?status=0&assignmentId='+row.assignmentId+'&activityId='+row.id+'" target="_blank" class="btn btn-info btn-xs">回评</a>';
    				return htmlStr;
    			}else{
    				return '<a href="javascript:void(0)" onclick="clickEditBtn(\''+row.assignmentId+'\',\''+row.id+'\')" target="_blank" class="btn btn-info btn-xs">编辑</a>';
    			}
	    	}}]
	});
}
function courseListView(){
	$('#nav li:first').addClass('active');
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li class="active">课程列表</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>课程列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'course/getCourses',
	    undefinedText:'',
	    striped:true,
	    idField:'id',
	    columns: [
	    	{field: 'year',title: '年份',width:100}, 
	    	{field: 'courseName',title: '课程名'},
	    	{field: 'op',title: '操作',width:100,formatter:function(value,row,index){
	    		return '<a href="javascript:assignmentListView(\''+row.id+'\',\''+row.courseName+'\');" class="btn btn-info btn-xs">进入</a>';
	    	}}]
	});
}
function assignmentListView(courseId,courseName){
	manageConst(courseId,courseName);
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li class="active">'+courseName+'</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>作业列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'assignment/getAssignments?courseId='+courseId,
	    undefinedText:'',
	    striped:true,
	    idField:'id',
	    columns: [
	    	{field: 'assignmentName',title: '作业名称'},
	    	{field: 'description',title: '作业描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
			{field: 'op',title: '操作',width:100,formatter:function(value,row,index){
				return '<a href="javascript:activityListView(\''+row.id+'\',\''+row.assignmentName+'\');" class="btn btn-info btn-xs">进入</a>';
			}}]
	});
}
function activityListView(assignmentId,assignmentName){
	manageConst(currentCourseId,currentCourseName,assignmentId,assignmentName);
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li><a href="javascript:assignmentListView(\''+currentCourseId+'\',\''+currentCourseName+'\');">'+currentCourseName+'</a></li><li class="active">'+assignmentName+'</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>活动列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'activity/getCanDoActivities?assignmentId='+assignmentId,
	    undefinedText:'',
	    idField:'id',
	    sortName:'startDate',
	    rowStyle:function rowStyle(row, index) {
	    	if(new Date(row.startDate)>new Date()){
	    		return {
					css: {"color": "#fff","background-color": "#bcd2d8"}
				};
    		}else if(new Date(row.startDate)<=new Date() &&　new Date(row.endDate)>new Date()){
    			return {
					css: {"color": "#fff","background-color": "#6de66b"}
				};
    		}else{
    			return {
					css: {"color": "#fff","background-color": "#bbb"}
				};
    		}
	    	
		},
	    columns: [
	    	{field: 'activityType',title: '活动状态',width:100,formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')>new Date()){
	    			return '即将开始';
	    		}else if(new Date(row.startDate+' 00:00:00')<=new Date() &&　new Date(row.endDate+' 00:00:00')>new Date()){
	    			return '正在进行';
	    		}else{
	    			return '已结束';
	    		}
	    	}},
	    	{field: 'activityName',title: '活动名称',width:'200'},
	    	{field: 'description',title: '活动描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
	    	{field: 'showVision',title: '群体感知显示',width:20,align:'center',formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')<=new Date()){
	    			if(row.activityType=="COMMENT"){
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}else if(row.activityType=="FEEDBACK"){
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}else{
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}
	    		}
	    	}},
	    	{field: 'op',title: '操作',width:180,formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')<=new Date() &&　new Date(row.endDate+' 00:00:00')>new Date()){
	    			if(row.activityType=="COMMENT"){
	    				return '<a href="/pad/comment.html?assignmentId='+row.assignmentId+'&activityId='+row.id+'" target="_blank" class="btn btn-info btn-xs">组内互评</a>';
	    			}else if(row.activityType=="FEEDBACK"){
	    				var htmlStr = '<div class="btn-group"><button class="btn btn-info btn-xs dropdown-toggle" type="button" id="dropdownMenu'+index+'" data-toggle="dropdown">组间互评<span class="caret"></span></button><ul class="dropdown-menu" style="position:relative;" role="menu" aria-labelledby="dropdownMenu'+index+'">';
	    				$.ajax({
	    					url:'/pad/assignment/getCommentAssignmentPad?activityId='+row.id,
		    	    		async: false,
	    					success:function(data){
	    						for(var i=0;i<data.assignmentPads.length;i++){
	    							if(data.assignmentPads[i]!=null)
	    							htmlStr += '<li role="presentation"><a role="menuitem" tabindex="-1" target="_blank" href="/pad/feedback.html?assignmentPadId='+data.assignmentPads[i].id+'&activityId='+row.id+'">'+data.assignmentPads[i].groupName+'</a></li>';
	    						}
	    					}
	    				});
	    				htmlStr +='</ul></div> <a href="/pad/edit?status=0&assignmentId='+row.assignmentId+'&activityId='+row.id+'" target="_blank" class="btn btn-info btn-xs">回评</a>';
	    				return htmlStr;
	    			}else{
	    				//return '<a href="/pad/edit?assignmentId='+row.assignmentId+'&activityId='+row.id+'" target="_blank" class="btn btn-info btn-xs">编辑</a>';
	    				return '<a href="javascript:void(0)" onclick="clickEditBtn(\''+row.assignmentId+'\',\''+row.id+'\')" target="_blank" class="btn btn-info btn-xs">编辑</a>';
	    			}
	    		}
	    	}}]
	});
}





var currentActivity = {};
function drawVision(dom,row){
	currentActivity = row;
	var activityId = row.id;
	if($(dom).is(':checked')){
		$.ajax({
			url:'/pad/activity/getActivityGroupVision?activityId='+activityId,
			cache:true,
			success:function(result){
				var info = activityId;
				if(result.code==0){
					var visions = result.data.vision==null?"":result.data.vision.vision==null?"":result.data.vision.vision;
					$('#visions').html('');
					if(visions==""){
						$('#visions').html('无');
					}
					if(visions.indexOf("1")>-1){// 编写专注度折线图
						drawFocusVision(activityId);
						info+="-line_chart";
					}
					if(visions.indexOf("2")>-1){// 编辑字数饼图
						drawGroupWordPie(activityId);
						info+="-pie";
					}
					if(visions.indexOf("3")>-1){// 编辑版本数柱状图
						drawGroupVersionBar(activityId);
						info+="-histogram";
					}
					if(visions.indexOf("4")>-1){// 组内互评雷达图
						drawGroupRadar(activityId);
						info+="-group_radar";
					}
					if(visions.indexOf("5")>-1){// 组内互评社会网络图
						drawRelationship(activityId);
						drawRelationshipB(activityId);
						info+="-group_social";
					}
					if(visions.indexOf("6")>-1){// 组间互评雷达图
						drawGroupBetweenRadar(activityId);
						drawCourseBetweenRadar(activityId);
						info+="-between_group_radar";
					}
					if(visions.indexOf("7")>-1){// 组间互评社会网络图
						drawCrouseBetweenRalationship(activityId);
						drawBetweenRelationship(activityId);
						info+="-between_group_social";
					}
					 if(visions.indexOf("8")>-1){// 组间互评策略建议       如果行为图出错，删掉下面保存行为
							$.ajax({
								url:'/pad/analysis/getGroupAdviceResult?activityId='+activityId,
								type:'GET',
								success:function(data){
									
									if(data=="true")
									{
							            drawGroupRadarAdvice(activityId);
									}
								}
							});
						    info+="-between_group_radar_advice";
						}
					 if(visions.indexOf("9")>-1){// 组间互评策略建议
						  drawGroupBetweenAdvice(activityId);
							info+="-between_group_comment_advice";
						}
					 
					 if(visions.indexOf("a")>-1){// 组间互评论次数建议
						  drawGroupBetweenTimesAdvice(activityId);
							info+="-between_group_comment_times_advice";
						}
					 
					 
				
				}
				$.ajax({
					url:'/pad/event/saveUserEvent?object='+info+'&action=click',
					type:'GET',
					success:function(){
					}
				});
			}
		});
	}
}
/**
 * 专注度图
 */
function drawFocusVision(activityId){

	$.ajax({
		url:'/pad/analysis/getFocus?activityId='+activityId,
		success:function(focusJson){
			//console.log(focusJson);
			if(!$('#selectTime').length>0){
				$('#visions').append('<div id="selectTime"><input id="startFilterTime" name="startFilterTime" class="date date-time"> - <input id="endFilterTime" name="endFilterTime" class="date date-time"> <input type="button" onclick="javascript:drawFocusVision(\''+activityId+'\')" value="过滤"></div>');
				$('.date-time').datetimepicker({
					autoclose: 1,
					format: 'yyyy-mm-dd hh:ii:ss',
					todayBtn:  1,
					todayHighlight: 1,
					forceParse: 1
				});
			}
			var startFilterTime = new Date($('#startFilterTime').val());
			var endFilterTime = new Date($('#endFilterTime').val());
			if(startFilterTime=="Invalid Date" || endFilterTime=="Invalid Date"){
				for(var n=0;n<focusJson.length;n++){
					var jsonData = focusJson[n].focus;
					if(jsonData!=null&&jsonData.length>0){
						//console.log("lenght"+n);
						if(focusJson.length>0){
							if(startFilterTime=="Invalid Date" || startFilterTime>new Date(jsonData[0].time)){
								//console.log(1);
								startFilterTime = new Date(jsonData[0].time);
							}
							if(endFilterTime=="Invalid Date" || endFilterTime<new Date(jsonData[jsonData.length-1].time)){
								endFilterTime = new Date(jsonData[jsonData.length-1].time);
								//console.log(2);
							}
						}
					}
				}
			}
			console.log(startFilterTime + "--" + endFilterTime);
			for(var n=0;n<focusJson.length;n++){
				$('#visions').append('<div class="echarts" id="foucs-chart'+n+'" style="height:320px;"></div>');
				var date = [];
				var data = [];
				var jsonData = focusJson[n].focus;
				var startDate = startFilterTime;
				var endDate = endFilterTime;
//				if(jsonData!=null&&jsonData.length>0){
//					startDate = new Date(jsonData[0].time);
//					endDate = new Date(jsonData[jsonData.length-1].time);
//				}
				var index = 0;
				if(startFilterTime!="Invalid Date" && endFilterTime!="Invalid Date"){
					for(var i=startFilterTime.getTime();i<endFilterTime.getTime();i=i+1000){
						date.push(new Date(i).format("yyyy-MM-dd hh:mm:ss"));
						var myflag = true;
						for(var j=index;jsonData!=null&&jsonData.length>0&&j<jsonData.length&&jsonData[j].time<i&&i<endDate.getTime();j++){
							if(jsonData[j].time-i>-1000 && jsonData[j].time-i<1000){
								data.push(jsonData[j].focus);
								myflag = false;
								break;
							}
						}
						if(myflag){
							data.push(0.0);
						}
					}
				}else{
					for (var i = 0;jsonData!=null && i < jsonData.length; i++) {
						date.push(new Date(jsonData[i].time).format("yyyy-MM-dd hh:mm:ss"));
						data.push(jsonData[i].focus);
					}
				}
				option = {
						title: {
					        text: '专注度-'+focusJson[n].user
					    },
						tooltip: {
							trigger: 'axis',
							position: function (pt) {
								return [pt[0], '1'];
							}
						},
						xAxis: {
							type: 'category',
							boundaryGap: false,
							data: date 
						},
						yAxis: {
							type: 'value',
							min:0,
							max:1
						},
						series: [
							{
								name:'专注度',
								type:'line',
								itemStyle: {
									normal: {
										color: 'rgb(255, 70, 131)'
									}
								},
								data: data
							}
							]
				};
				
				var myChart = echarts.init(document.getElementById('foucs-chart'+n));
				myChart.setOption(option);
			}
		}
	});
	
}
function getData(activityId){
	$.ajax({
		url:'/pad/anyComment?activityId='+activityId+'&userid='+currentUserId,
		async: false,
		success:function(FbcommentQua){
			ctimes=FbcommentQua.commentCount;
			bctimes=FbcommentQua.becommentCount;
			score=FbcommentQua.commentScore;
			
		}
	});
	$.ajax({
		url:'/pad/anyCommentType?activityId='+activityId+'&userid='+currentUserId,
		async: false,
		success:function(commentType_){
			this.commentType=commentType_;
		}
	});
}

function print(){

	if($('#myChart').length<=0){
		$('#visions').append('<div align="center" style="width: 400px; margin:0 auto;"><h4>下面是你的评论数据雷达图:</h4><canvas id="myChart"></canvas></div>');
		$('#visions').append('<div align="center" style="width: 400px; margin:0 auto;"><h4>下面是你的评论回馈雷达图:</h4><canvas id="myChart2"></canvas></div>');
	}
	// 1 获取一个画布对象 ，也就是将要产生图标的位置
	var ctx = document.getElementById("myChart").getContext("2d");
	var ctx2 = document.getElementById("myChart2").getContext("2d");
	var labelArr = [];
	var dataArr = [];
	for(var i=0;i<commentType.length;i++){
		labelArr.push(commentType[i].typeName);
		dataArr.push(commentType[i].typeValue);
	}
	var data = {			
		    labels: ["commentTimes", "beCommentTimes", "avgScore"],
		    datasets: [
		               
		        {
		            label: currentUserName,
		            backgroundColor: "rgba(255,99,132,0.2)",
		            borderColor: "rgba(255,99,132,1)",
		            pointBackgroundColor: "rgba(255,99,132,1)",
		            pointBorderColor: "#000",
		            pointHoverBackgroundColor: "#000",
		            pointHoverBorderColor: "rgba(179,181,198,1)",
		            data: [ctimes, bctimes, score]
		        }
   
		]};
	
	var data2 = {			
		    labels: labelArr,
		    datasets: [
		               
		        {
		            label: currentUserName,
		            backgroundColor: "rgba(255,99,132,0.2)",
		            borderColor: "rgba(255,99,132,1)",
		            pointBackgroundColor: "rgba(255,99,132,1)",
		            pointBorderColor: "#000",
		            pointHoverBackgroundColor: "#000",
		            pointHoverBorderColor: "rgba(179,181,198,1)",
		            data: dataArr
		        }
		        ]};
	var myRadarChart = new Chart(ctx, {
	    type: 'radar',
	    data: data,
	    options: options
	});
	var myRadarChart2 = new Chart(ctx2, {
	    type: 'radar',
	    data: data2,
	    options: options
	});
	var options={
	    scale: {
	        reverse: false,
	        ticks: {
	            beginAtZero: false
	        },
	        type:'radialLinear'
	    } 
	  
	    
	}
	// 显示图表
	 $('#radarChar').css("display","block");
}

//zdb 建议：针对组内雷达图数据   组内互评建议
function drawGroupRadarAdvice(activityId){
	var loginuser;
	var userAdvice=new Array();
	
	$.ajax({
		async: false,		
		url:'/pad/getSessionUser',
		success:function(data){
			
			loginuser=data;
			
		}
	});
	
	$.ajax({
		url:'/pad/analysis/getGroupRadar?activityId='+activityId,
		success:function(data){
			var userData=[];
			
			if(data.radar.length>0){
				for(var i=0;i<data.radar.length;i++){
				 if(data.radar[i].user==loginuser.realname){
				    userData=data.radar[i];
				 }
				}
			}
			
			//排序找到 最大 和最小 分数 的维度
			  for(var i=0;i<userData.tempList.length;i++){
					var t=i;
					for(var j=i+1;j<userData.tempList.length;j++){
						if(userData.tempList[t].score<userData.tempList[j].score)
							{ 
							  t=j;
							}
					}
					if(i!=t){
						var temp=[];
						temp=userData.tempList[i];
						userData.tempList[i]=userData.tempList[t];
						userData.tempList[t]=temp;
					}
				}
			  
			  if($('#group-word-radar-advice').length<=0){
				  $('#visions').prepend('<div id="group-word-radar-advice" style="height:100%;width:1140px;"></div>');
				}
			
			$('#group-word-radar-advice').append('<p><span style="font-size:15px;font-weight:bold;">'+userData.user+'</span> 同学<p>');
			$('#group-word-radar-advice').append('你的  ');
			
			for(var i=0;i<userData.tempList.length;i++){
				if(userData.tempList[i].score==userData.tempList[0].score){
					$('#group-word-radar-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+userData.tempList[i].question+'</span> 分数为 '+userData.tempList[i].score.toFixed(2)+' ');
				}
			}
			
			$('#group-word-radar-advice').append(' 表现不错！继续保持！ ');
			$('#group-word-radar-advice').append('但是很遗憾，你的协作学习能力在');
			
			for(var i=0;i<userData.tempList.length;i++){
				if(userData.tempList[i].score==userData.tempList[userData.tempList.length-1].score){
					userAdvice.push(userData.tempList[i].question);
					$('#group-word-radar-advice').append('<span style="font-size:20px;font-weight:bold;color:red;">'+userData.tempList[i].question+'</span> 维度分数为 '+userData.tempList[i].score.toFixed(2)+' ');
				}
			}
			
			$('#group-word-radar-advice').append(' 能力较弱！还需努力！');
			$('#group-word-radar-advice').append(' 我们为你提出了针对性的策略:<br>');
			//读取本地建议文件
			  var hasOne=false;
			$.ajax({
				   async: false,	
				   url: "./resources/json/groupAdvice.json",//json文件位置
				   type: "GET",//请求方式为get
				   dataType: "json", //返回数据格式为json
				   success: function(data) {//请求成功完成后要执行的方法 
				       //each循环 使用$.each方法遍历返回的数据date
				       $.each(data.groupAdvice,function(i,item) {
				         //存取建议  等待输出
				    	  for(var j=0;j<userAdvice.length;j++)
				    	   {      
				    		      
				    		     if(userAdvice[j]==item.name)
	                            	{
					    				   $('#group-word-radar-advice').append('<span style="font-size:20px;font-weight:bold;color:red;">'+item.name+':</span>'+':'+item.explain+'<br>建议: '+item.advice+'<br>'); 
					    			 }
					    		   
	                            	   
	                            	
				    	   }   	    	  
				       })
				   }
				})
				
		
		}
	});
}

//组间策略建议
function drawGroupBetweenAdvice(activityId){
	var loginuser;//realname 是名字
	var groupBetweenData=[];//存储 组间建议回调数据
	$.ajax({
		
		async: false,
		url:'/pad/getSessionUser',
		success:function(data){
			loginuser=data;
		}
	});
	$.ajax({
		   async: false,		 
		   url: "./resources/json/groupAdvice.json",//json文件位置
		   type: "GET",//请求方式为get
		   dataType: "json", //返回数据格式为json
		   success: function(data) {//组间建议数据
			   groupBetweenData=data.groupBetweenAdvice;
		   }
		});
	
	
	
	if($('#group-version-between-advice').length<=0){
		$('#visions').prepend('<div  id="group-version-between-advice" style="height:100%;width:1140px;"></div>');
	}
	
	$.ajax({
		url:'/pad/analysis/getGroupBetweenRadar?activityId='+activityId,
		success:function(data){
		    var indicate=[];//维度
		    var userScore=[];//存储 当前用户的 反馈分数 数据
			var userAdviceMap={};//3 个  键位   name 小维度  advice 建议（好或者坏 都可以）  dim 父维度      
			var userAdviceMapList=[];//存放用户 advice  map 的list
			if(data.data.length>0){
				for(var i=0;i<data.data[0].length;i++){// 获取所有维度，从第一条数据去取
					indicate[i]=data.data[0][i].type;
				}
			}
			
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){
					if(loginuser.realname==data.data[i][0].author){//得到 登录用户 名称,取出数据
					      userScore=data.data[i];
					}
				}
			}
			
			//分析 并给出建议  1先从质量上来说 ，分数为 0 不用处理 ，不为0  大于3 为优秀  小于等于2 为差
			$('#group-version-between-advice').append('<p><span style="font-size:15px;font-weight:bold;">'+loginuser.realname+'</span> 同学<p>');
			$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;">一 </span> 你给出的评论的反馈情况如下：<br>');
			
			var allZero=true;//全是0
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score!=0){
					allZero=false;
				}
			}
			
			if(allZero==true){//全是0 
				$('#group-version-between-advice').append('很遗憾，你未能给出有效反馈。如果遇到什么问题希望你能及时向老师，同学反映，大家会尽力帮助你的。加油哦！')
			}else{   //说明至少 有一条不是 0 可以进行下面的分析
			//先找出 优秀的 >3
			var hasGood=false;
			var hasBad=false;
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score>3){
					hasGood=true;//有优秀的
				}
				if(userScore[i].score<=2&&userScore[i].score>0){
					hasBad=true;//有 表现差的
				}
			}
		    
			/*if(hasGood==false&&hasBad==false){
				$('#group-version-between-advice').append('表现适中，暂无建议！');
			}*/
	       
			if(hasGood==true){
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score>3){
					$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+userScore[i].type+':</span>');
					for(var j=0;j<groupBetweenData.length;j++){
						if(groupBetweenData[j].name==userScore[i].type){
							$('#group-version-between-advice').append(groupBetweenData[j].adviceToGood+'<br>');
						}
					}
				}
			}
		   }
			
			//找出表现不佳的 并给出建议
			if(hasBad==true){
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score<=3&&userScore[i].score>0){
					$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:red;">'+userScore[i].type+':</span>');
					for(var j=0;j<groupBetweenData.length;j++){
						if(groupBetweenData[j].name==userScore[i].type){
							$('#group-version-between-advice').append(groupBetweenData[j].adviceToBad+'<br>');
						}
					}
				}
			}
			}//给出 坏的建议  if 结束   条件：hasBad=true
			
			
			//2   从数量上去总结
			$('#group-version-between-advice').append('<br><span style="font-size:20px;font-weight:bold;">二 </span>系统给出的总结情况如下:<br>');
			var dataList=[];//存放map的list
			for(var i=0;i<groupBetweenData.length;i++){
				
				if(groupBetweenData[i].dim!="无关"){
				  var dataMap={};// 两个 键位 dim 维度 名称 ，state 有无状态码 有为  1 无为0
				  if(i==0){
					dataMap["name"]=groupBetweenData[i].dim;
					dataMap["state"]="0";
					dataList.push(dataMap);
				  }
				   var hasOne=false;
				   for(var j=0;j<dataList.length;j++){
					   if(dataList[j].name==groupBetweenData[i].dim){
						   hasOne=true;
					   }
				   }
				   if(hasOne==false){
					    dataMap["name"]=groupBetweenData[i].dim;
						dataMap["state"]="0";
						dataList.push(dataMap);
				   }
				   
				}// 不等于无关  条件 结束
		    }// 构造  维度出现 情况 数组 结束
			
			
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score>0&&userScore[i].type!="其他"){
				for(var j=0;j<groupBetweenData.length;j++){
					if(userScore[i].type==groupBetweenData[j].name){
						for(var k=0;k<dataList.length;k++){
							if(dataList[k].name==groupBetweenData[j].dim){
								dataList[k].state="1";
							}
						}
					}
				}
			}
			}//计算 有反馈的维度  结束
			
			
			
			var effectCount=0;//有效反馈条数
			for(var i=0;i<userScore.length;i++){
				if(userScore[i].score>0&&userScore[i].type!="其他"){
					effectCount++;
				}
			}
			
			var effectDim=0;//有效 反馈维度
			for(var i=0;i<dataList.length;i++){
				if(dataList[i].state=="1"){
					effectDim++;
				}
			}
		    
			
			if(effectDim==1){
				$('#group-version-between-advice').append('很遗憾，你给出的有效反馈共'+effectCount+'条,包括&nbsp;');
				for(var i=0;i<userScore.length;i++){
					if(userScore[i].score>0&&userScore[i].type!="其他"){
						$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+userScore[i].type+'</span>&nbsp;、')
					}
				}
				$('#group-version-between-advice').append('类别,仅涉及');
				for(var i=0;i<dataList.length;i++){
					if(dataList[i].state=="1"){
						$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+dataList[i].name+'</span>&nbsp;维度,');
					}
				}
				$('#group-version-between-advice').append('还有');
				for(var i=0;i<dataList.length;i++){
					if(dataList[i].state=="0"){
						$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:red;">'+dataList[i].name+'</span>&nbsp;维度,');
					}
				}
				$('#group-version-between-advice').append('两个维度等你两个维度在等待着你开启哦。快去评论吧！多多给出其他反馈，加油！');
			  }else if(effectDim==2){
				  $('#group-version-between-advice').append('真棒！你给出的有效反馈共'+effectCount+'条,包括&nbsp;');
					for(var i=0;i<userScore.length;i++){
						if(userScore[i].score>0&&userScore[i].type!="其他"){
							$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+userScore[i].type+'</span>、&nbsp;')
						}
					}
					$('#group-version-between-advice').append('类别,涉及');
					for(var i=0;i<dataList.length;i++){
						if(dataList[i].state=="1"){
							$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+dataList[i].name+'</span>&nbsp;维度,');
						}
					}
					$('#group-version-between-advice').append('只剩');
					for(var i=0;i<dataList.length;i++){
						if(dataList[i].state=="0"){
							$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:red;">'+dataList[i].name+'</span>&nbsp;维度,');
						}
					}
					$('#group-version-between-advice').append('在等待着你开启哦。快去评论吧！');
			  }else{
				  $('#group-version-between-advice').append('给你点赞！你给出的有效反馈共'+effectCount+'条,包括&nbsp;');
					for(var i=0;i<userScore.length;i++){
						if(userScore[i].score>0&&userScore[i].type!="其他"){
							$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+userScore[i].type+'</span>、&nbsp;')
						}
					}
					$('#group-version-between-advice').append('类别,共涉及&nbsp;');
					for(var i=0;i<dataList.length;i++){
						if(dataList[i].state=="1"){
							$('#group-version-between-advice').append('<span style="font-size:20px;font-weight:bold;color:green;">'+dataList[i].name+'</span>、');
						}
					}
					$('#group-version-between-advice').append('三个维度哦。希望你能再接再厉，快去评论吧！');
			  }
			
			
			
			}//  大 else  end  从   allZero=0  判断条件开始
			
		}
	});
}

/*
 * 组间互评次数建议
 */
function drawGroupBetweenTimesAdvice(activityId){
	var loginuser;
	if($('#group-between-comment-times-advice').length<=0){
		$('#visions').prepend('<div  id="group-between-comment-times-advice" style="height:100%;width:1140px;"></div>');
	}
	
	$.ajax({
		async: false,
		url:'/pad/getSessionUser',
		success:function(data){
			loginuser=data;
			
		}
	});
	$('#group-between-comment-times-advice').append('<p><span style="font-size:15px;font-weight:bold;">'+loginuser.realname+'</span> 同学<p>');
	
	 $.ajax({
			url:'/pad/analysis/getBetweenRelationshipB?activityId='+activityId,
			success:function(data){
	            var compareResult=[];//存储 当前用户  与互评小组 人员交互 次数
				var groupUsers=[];
				var addList=[];//添加 评论
				var replyList=[];//回复
				var gradeList=[];//打分
				groupUsers=data.data[0].groupUsersList;//拿到本组人员
				addList=data.data[0].addCommentList;//add
				replyList=data.data[0].replyList;//reply
				gradeList=data.data[0].gradeList;//grade
				for(var i=0;i<groupUsers.length;i++){
					if(groupUsers[i]!=loginuser.realname){//不是 本人 统计交互次数
						var communicateMap={};
						var count=0;
						communicateMap["name"]=groupUsers[i];
						//先 遍历 add  再reply  最后grade   计算三者总次数
						//add
						for(var j=0;j<addList.length;j++){
							for(var k=0;k<addList[j].length;k++){
								if((addList[j][k].author==loginuser.realname)&&(groupUsers[i]==addList[j][k].commenter)){
									count+=addList[j][k].times;
								}
							}
						}
						//reply
						for(var j=0;j<replyList.length;j++){
							for(var k=0;k<replyList[j].length;k++){
								if((replyList[j][k].Replyer==loginuser.realname)&&(groupUsers[i]==replyList[j][k].author)){
									count+=replyList[j][k].times;
								}
							}
						}
						//grade
						for(var j=0;j<gradeList.length;j++){
							for(var k=0;k<gradeList[j].length;k++){
								if((gradeList[j][k].grader==loginuser.realname)&&(groupUsers[i]==gradeList[j][k].author)){
									count+=gradeList[j][k].times;
								}
							}
						}
						communicateMap["count"]=count.toString();
						compareResult.push(communicateMap);
						
					}
				}// 遍历组员 结束
				var allZero=true;//判断 是否 与组员交互过
				for(var i=0;i<compareResult.length;i++){
					if(Number(compareResult[i].count)>0){
						allZero=false;
					}
				}
				
				if(allZero==true){
					$('#group-between-comment-times-advice').append('你还没有与任何一位组员进行交互，请尽快和同伴进行交流吧！');
				}else{
					var max=compareResult[0].count;
					var min=compareResult[0].count;
					for(var i=0;i<compareResult.length;i++){
						if(Number(compareResult[i].count)>max){
							max=Number(compareResult[i].count);//找到最大值
						}
						if(Number(compareResult[i].count)<=min){
							min=Number(compareResult[i].count);//找到最小值
						}
					}
					$('#group-between-comment-times-advice').append('亲~恭喜你！和');
					for(var i=0;i<compareResult.length;i++){
						if(Number(compareResult[i].count)==max){
							$('#group-between-comment-times-advice').append('&nbsp'+'<span style="font-size:20px;font-weight:bold;color:green;">'+compareResult[i].name+'</span>');	
						}
					}
					$('#group-between-comment-times-advice').append('（交流最多的）合作的非常愉快，积极地相互交流学习，但是也别忘了');
					for(var i=0;i<compareResult.length;i++){
						if(Number(compareResult[i].count)==min){
							$('#group-between-comment-times-advice').append('&nbsp'+'<span style="font-size:20px;font-weight:bold;color:red;">'+compareResult[i].name+'</span>');	
						}
					}
					$('#group-between-comment-times-advice').append('（交流最少的）也是我们中的一员哦，大家要多多沟通，共同进步哦。');
					
				}
				
				
			}
		});

	
	
}







/**
 * 组内雷达图
 */
function drawGroupRadar(activityId){
	
	if($('#group-word-radar').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-radar" style="height:400px;"></div>');
	}
	if($('#group-word-radar1').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-radar1" style="height:400px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupRadar?activityId='+activityId,
		success:function(data){

			var max=0;
			var showLegendData=[];
			var showDataIndicator=[];
			var showDataScore=[];
			if(data.radar.length>0){
				for(var i=0;i<data.radar.length;i++){
				
					showLegendData.push(data.radar[i].user);
				}
			}
			if(data.radar.length>0){
				for(var i=0;i<data.radar.length;i++){
					var temp={};
					var score=[];
					if(data.radar[i].tempList.length>0){
						for(var j=0;j<data.radar[i].tempList.length;j++){
							if(data.radar[i].tempList[j].score>max){
								max=Number(data.radar[i].tempList[j].score).toFixed(2);
							}
							score.push(Number(data.radar[i].tempList[j].score).toFixed(2));
						}
					}
					else{
						for(var j=0;j<data.question.length;j++){
							score.push(0.00);
						}
					}
					temp.value=score;
					temp.name=data.radar[i].user;
					showDataScore.push(temp);
				}
			}
			if(data.question.length>0){
				for(var i=0;i<data.question.length;i++){
					var temp={};
					if(i==0){
						var showinfo={};
						var textStyle={};
						showinfo.show=true;
						showinfo.formatter = function(value,index){return value.toFixed(2)};
						textStyle.fontSize=10;
						textStyle.color='#333';
						showinfo.textStyle=textStyle;
						temp.axisLabel=showinfo;
					}
					temp.text=data.question[i];
					temp.max=max;
					showDataIndicator.push(temp);
				}
			}
			else{
				alert("请导入互评模板");
			}

			option = {
					title: {
					      text: '本组成员-协同学习情况分析'
					},
					tooltip: {
						trigger: 'axis'
					},
				    legend: {
				   
				    	top:[20],
				    	x: 'center',
				        data: showLegendData,
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: showDataIndicator,
				        radius:120  
				    },
				    series: [{
				        type: 'radar',
				        tooltip: {
			                trigger: 'item'
			            },
				        // areaStyle: {normal: {}},
				        data : showDataScore
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-word-radar'));
			myChart.setOption(option);
		}
	});
	$.ajax({
		// 数据发送错误 应该发送组内的平均值
		url:'/pad/analysis/getMutualCourseRadar?activityId='+activityId,
		success:function(data){

			var max=0;
			var legendGroups=[];
			var indicatorGroupsData=[];
			var dataGroupsScore=[];
			
			var showLegendGroups;
			var showIndicatorGroupsData;
			var showDataGroupsScore;
			
			if(data.radar.length>0){
				for(var i=0;i<data.radar.length;i++){
					dataGroupsScore[i]=new Array();
					legendGroups.push(data.radar[i].groupName);
					if(i==0){
						for(var j=0;j<data.radar[0].radar.question.length;j++){
							indicatorGroupsData.push(data.radar[0].radar.question[j]);
						}
					}
					for(var j=0;j<data.radar[i].radar.score.length;j++){
						dataGroupsScore[i][j]=Number(data.radar[i].radar.score[j]).toFixed(2).toString();
						if(max<dataGroupsScore[i][j]){
							max=Number(dataGroupsScore[i][j]).toFixed(2).toString();
						}
					}
				}
				showLegendGroups="[";
				for(var i=0;i<legendGroups.length;i++){
					if(i==legendGroups.length-1){
						str="\'"+legendGroups[i]+"\']";
						showLegendGroups+=str;
					}
					else{
						str="\'"+legendGroups[i]+"\',";
						showLegendGroups+=str;
					}
				}
				showLegendGroups=eval(showLegendGroups);
				showIndicatorGroupsData="[";
				for(var i=0;i<indicatorGroupsData.length;i++){
					if(i==indicatorGroupsData.length-1){
						str="{text:"+"\'"+indicatorGroupsData[i]+"\',max:"+max+"}]";
						showIndicatorGroupsData+=str;
					}
					else{
						if(i==0){
							str="{text:"+"\'"+indicatorGroupsData[i]+"\',axisLabel: {show: true,formatter: function(value,index){return value.toFixed(2)}, textStyle: {fontSize: 10, color: '#333'}},max:"+max+"},";
							
						}
						else{
							str="{text:"+"\'"+indicatorGroupsData[i]+"\',max:"+max+"},";
						}
						showIndicatorGroupsData+=str;
					}
				}

				showIndicatorGroupsData=eval(showIndicatorGroupsData);
				showDataGroupsScore="[";
				for(var i=0;i<legendGroups.length;i++){
					if(legendGroups.length-1==i){
						str="{value:[";
						showDataGroupsScore+=str;
						for(var j=0;j<indicatorGroupsData.length;j++){
							if(j==indicatorGroupsData.length-1){
								str=Number(dataGroupsScore[i][j]).toFixed(2).toString()+"],name:\'"+legendGroups[i]+'\'}]';
								showDataGroupsScore+=str;
							}
							else{
								str=Number(dataGroupsScore[i][j]).toFixed(2).toString()+",";
								showDataGroupsScore+=str;
							}
						}
					}
					else{
						str="{value:[";
						showDataGroupsScore+=str;
						for(var j=0;j<indicatorGroupsData.length;j++){
							if(j==indicatorGroupsData.length-1){
								str=Number(dataGroupsScore[i][j]).toFixed(2).toString()+"],name:\'"+legendGroups[i]+'\'},';
								showDataGroupsScore+=str;
							}
							else{
								str=Number(dataGroupsScore[i][j]).toFixed(2).toString()+",";
								showDataGroupsScore+=str;
							}
						}
					}
				}
				showDataGroupsScore=eval(showDataGroupsScore);
			}
			option = {
					title: {
					      text: '全班学生-协同学习情况分析'
					},
					tooltip: {
						trigger: 'axis'
					},
				    legend: {
				    	top:[20],
				        data: showLegendGroups
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: showIndicatorGroupsData,
				        radius:120  
				    },
				    series: [{
				        tooltip: {
			                trigger: 'item'
			            },
			            type: 'radar',
				        // areaStyle: {normal: {}},
				        data : showDataGroupsScore
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-word-radar1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组内文字饼图
 */
function drawGroupWordPie(activityId){
	if($('#group-word-pie').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-pie" style="height:400px;"></div>');
	}
	if($('#group-word-pie1').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-pie1" style="height:400px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupWordPie?activityId='+activityId,
		success:function(data){
			var pieData = [];
			for(var i=0;i<data.pie.length;i++){
				var tempData = {};
				tempData.value = data.pie[i].wordCount;
				tempData.name = data.pie[i].user;
				pieData.push(tempData);
			}
			option = {
			    title : {
			        text: '小组成员编辑字数',
			        subtext: data.groupName,
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    series : [
			        {
			            name: '字数编辑总量',
			            type: 'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:pieData,
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-word-pie'));
			myChart.setOption(option);
		},
		error:function(err){
			alert("饼图后台出错");
		}
	});
	$.ajax({
		url:'/pad/analysis/getCourseWordPie?activityId='+activityId,
		success:function(data){
			var pieData = [];
			var tempData = {};
			tempData.value = data.wordCount;
			tempData.name = "班级平均";
			pieData.push(tempData);
			option = {
			    title : {
			        text: '班级平均编辑字数',
			        subtext: data.groupName,
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    series : [
			        {
			            name: '字数编辑总量',
			            type: 'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:pieData,
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-word-pie1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组内版本数柱状图
 */
function drawGroupVersionBar(activityId){
	if($('#group-version-bar').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-bar" style="height:400px;"></div>');
	}
	if($('#group-version-bar1').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-bar1" style="height:400px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupVersionBar?activityId='+activityId,
		success:function(data){
			var xAxisData = [];
			var barData = [];
			for(var i=0;i<data.bar.length;i++){
				xAxisData.push(data.bar[i].user);
				barData.push(data.bar[i].versionCount);
			}
			option = {
				title : {
			        text: '小组成员编辑版本数',
			        subtext: data.groupName,
			        x:'center'
			    },
				color: ['#3398DB'],
			    tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
			    grid: {
			        left: '3%',
			        right: '4%',
			        bottom: '3%',
			        containLabel: true
			    },
			    xAxis : [
			        {
			            type : 'category',
			            data : xAxisData,
			            axisTick: {
			                alignWithLabel: true
			            }
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'版本数',
			            type:'bar',
			            barWidth: '60%',
			            data:barData
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-bar'));
			myChart.setOption(option);
		}
	});
	$.ajax({
		url:'/pad/analysis/getCourseVersionBar?activityId='+activityId,
		success:function(data){
			var xAxisData = [];
			var barData = [];
			xAxisData.push("班级平均");
			barData.push(data.versionCount);
			option = {
				title : {
			        text: '班级平均编辑版本数',
			        subtext: data.groupName,
			        x:'center'
			    },
				color: ['#3398DB'],
			    tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
			    grid: {
			        left: '3%',
			        right: '4%',
			        bottom: '3%',
			        containLabel: true
			    },
			    xAxis : [
			        {
			            type : 'category',
			            data : xAxisData,
			            axisTick: {
			                alignWithLabel: true
			            }
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'版本数',
			            type:'bar',
			            barWidth: '60%',
			            data:barData
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-bar1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组间关系图
 */
function drawRelationship(activityId){
	if($('#group-version-relationship').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-relationship" style="height:500px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getMutualtRelationship?activityId='+activityId,
		success:function(data){

			var pointsLink=[];// 该数据用于显示连接
			var pointsData=[];// 该数据用于存放社会网络图的人的节点
			var scoreArray=[];
			var scoreTemp;
			for(var i=0;i<data.groupUsersList.length;i++){
				var temp={};
				var item={};
				var normal={};
				normal.color ='#AE0000'
				item.normal=normal;
				temp.itemStyle=item;
				temp.name=data.groupUsersList[i];
				temp.x=Math.floor(Math.random()*1000+1);
				temp.y=Math.floor(Math.random()*200+1);
				temp.draggable = true;
				pointsData.push(temp);
			}
			for(var i=0;i<data.addCommentList.length;i++){
				if(data.addCommentList[i].length!=null){
					for(var j=0;j<data.addCommentList[i].length;j++){
						if(data.addCommentList[i][j].author!=data.addCommentList[i][j].commenter){
							var temp={};
							var sTemp={};
							var lTemp={};
							var normalTemp={};
							temp.source=data.addCommentList[i][j].author;
							temp.target=data.addCommentList[i][j].commenter;
							temp.name="addComment "+data.addCommentList[i][j].times;
							sTemp.trigger='item';
							sTemp.formatter=function(params,ticket,callback){
								return params.data.name;
								};
							lTemp.show=true;
							normalTemp.formatter=function(params, ticket, callback){
									var returnInfo =[];
									returnInfo = params.data.name.split(" ")
									return " C:"+returnInfo[1];
								};
							lTemp.normal=normalTemp;
							temp.label=lTemp;
							temp.tooltip=sTemp;
							pointsLink.push(temp);
						}
					}
				}
			}
			for(var i=0;i<data.replyList.length;i++){
				if(data.replyList[i].length!=null){
					for(var j=0;j<data.replyList[i].length;j++){
						if(data.replyList[i][j].Replyer!=data.replyList[i][j].author){
							var hasOne = false;
							for(var k=0;k<pointsLink.length;k++){
								if(pointsLink[k].source==data.replyList[i][j].Replyer&&pointsLink[k].target==data.replyList[i][j].author){
									hasOne = true; 
									pointsLink[k].name+=" Reply "+data.replyList[i][j].times;
									pointsLink[k].label.normal.formatter=function(params,ticket,callback){
													var returnInfo = params.data.name.split(" ");
													return " C:"+returnInfo[1]+" R:"+returnInfo[3];
												};
								}
							}
							if(hasOne == false){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=data.replyList[i][j].Replyer;
								temp.target=data.replyList[i][j].author;
								temp.name="Reply "+data.replyList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								normalTemp.formatter=function(params,ticket,callback){
									var returnInfo = params.data.name.split(" ");
									return " R:"+ returnInfo[1];
								};
								lTemp.show=true;
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
			}
			for(var i=0;i<data.gradeList.length;i++){
				if(data.gradeList[i].length!=null){
					for(var j=0;j<data.gradeList[i].length;j++){
						var hasOne = false;
						for(var k=0;k<pointsLink.length;k++){
							if(data.gradeList[i][j].grader==pointsLink[k].source&&data.gradeList[i][j].author==pointsLink[k].target){
								hasOne = true;
								pointsLink[k].name+=" Grade "+data.gradeList[i][j].times;

								pointsLink[k].label.normal.formatter=function(params,ticket,callback){
													var listTemp = params.data.name.split(" ");
													var returnTemp = null;

													if(listTemp.length>5){
														returnTemp=" C:"+listTemp[1]+" R:"+listTemp[3]+" G:"+listTemp[5];
													}
													else{
														if(listTemp[0]=="addComment"){
															returnTemp=" C:"+listTemp[1]+" G:"+listTemp[3];
														}
														else if(listTemp[0]=="Reply"){
															returnTemp=" R:"+listTemp[1]+" G:"+listTemp[3];
														}
													}
													return returnTemp;
												};
							}
						}
						if(hasOne == false){
							var temp={};
							var sTemp={};
							var lTemp={};
							var normalTemp={};
							temp.source=data.gradeList[i][j].grader;
							temp.target=data.gradeList[i][j].author;
							temp.name="Grade "+data.gradeList[i][j].times;
							sTemp.trigger='item';
							sTemp.formatter=function(params,ticket,callback){
								return params.data.name;
								};
							lTemp.show=true;
							normalTemp.formatter=function(params,ticket,callback){
									var returnInfo = params.data.name.split(" ");
									return " G:"+returnInfo[1];
								};
							lTemp.normal=normalTemp;
							temp.label=lTemp;
							temp.tooltip=sTemp;
							pointsLink.push(temp);
						}
					}
				}
			}
			for(var i=0;i<pointsLink.length;i++){
				var temp0 = {};
				var source = pointsLink[i].source;
				var name = pointsLink[i].name;
				var scoreList = name.split(" ");
				var score=0;
				var hasOne=false;
				if(scoreList.length>5){
					score = Number(scoreList[1])+Number(scoreList[3])+Number(scoreList[5]);
				}
				else if(scoreList.length>3){
					score = Number(scoreList[1])+Number(scoreList[3]);
				}
				else{
					score = Number(scoreList[1]);
				}
				for(var j=0;j<scoreArray.length;j++){
					if(scoreArray[j].source==source){
						hasOne=true;
						scoreArray[j].score+=score;
					}
				}
				if(hasOne==false){
					temp0.source= source;
					temp0.score = score;
					scoreArray.push(temp0);
				}
			}
			if(scoreArray.length>1){
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<scoreArray.length;j++){
						if(Number(scoreArray[i].score)>Number(scoreArray[j].score)){
							var scoreTemp = scoreArray[i];
							scoreArray[i]=scoreArray[j]
							scoreArray[j]=scoreTemp;
						}
					}
				}
			}

			if(scoreArray.length>=3){
				var colorTemp = parseInt(scoreArray.length/3);
			}
			else{
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#0072E3';
						}
					}
				}
			}

			for(var i=0;i<2*colorTemp;i++){
				if(i<colorTemp){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#07ac72';
						}
					}
				}
				else if(i<(2*colorTemp)){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#f90';
						}
					}
				}
			}
			option = {
			    title: {
			        text: '成员交互分析',
			        x:'center'
			    },
			    tooltip:{
					trigger:'axis'
				},
				animationDurationUpdate:1500,
				animationEasingUpdate:'quinticInOut',
			    series : [
			        {
			            type: 'graph',
			            layout: 'force',
			            symbolSize: 50,
			            roam: true,
			            force: {
		                    repulsion: 5000
		                },
			            tooltip:{
			            	trigger:'item'
			            },
			            label: {
			                normal: {
			                    show: true
			                }
			            },
			            edgeSymbol: ['circle', 'arrow'],
			            edgeSymbolSize: [4, 8],
			            edgeLabel: {
			                normal: {
			                	show:true,
			                    textStyle: {
			                        fontSize: 15
			                    }
			                }
			            },
			            lineStyle:{
			            	normal:{
			            		opacity:1,
			            		width:2,
			            		curveness:0.1
			            	}
			            },
			            data: pointsData,
			            // links: [],
			            links: pointsLink
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-relationship'));
			myChart.setOption(option);
		}
	});
}







//组间雷达图
function drawGroupBetweenRadar(activityId){

	if($('#group-version-Radarbar').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-Radarbar" style="height:400px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupBetweenRadar?activityId='+activityId,
		success:function(data){
			var showLegendGroups=[];
			var showIndicatorGroupsData=[];
			var showDataGroupsScore=[];
			var max =0; 
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){// 获取所需显示的小组的人
					showLegendGroups.push(data.data[i][0].author);
				}
			}
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){// 获取最大值
					for(var j=0;j<data.data[i].length;j++){
						if(max<data.data[i][j].score){
							max=Number(data.data[i][j].score).toFixed(2);
						}
					}
				}
			}
			if(data.data[0].length>0){
				for(var j=0;j<data.data[0].length;j++){
					var type={};
					if(j==0){
						var showinfo={};
						var textStyle={};
						showinfo.show=true;
						showinfo.formatter=function(value,index){return value.toFixed(2)};
						textStyle.fontSize=10;
						textStyle.color='#333';
						showinfo.textStyle=textStyle;
						type.axisLabel=showinfo;
					}
					type.text=data.data[0][j].type;
					type.max = max;
					showIndicatorGroupsData.push(type);
				}
			}
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){
					var temp={};
					var scoreList = [];
					if(data.data[i].length>0){
						for(var j=0;j<data.data[i].length;j++){
							scoreList.push(Number(data.data[i][j].score).toFixed(2));
						}
					}
					temp.value=scoreList;
					temp.name=data.data[i][0].author;
					showDataGroupsScore.push(temp);
				}
			}

			option = {
					title: {
					      text: '小组同伴互评情况分析'
					},
					tooltip: {
						trigger: 'axis'
					},
				    legend: {
				    	top:[20],
				        data: showLegendGroups
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: showIndicatorGroupsData,
				        radius:120  
				    },
				    series: [{
				        tooltip: {
			                trigger: 'item'
			            },
			            type: 'radar',
				        // areaStyle: {normal: {}},
				        data : showDataGroupsScore
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-version-Radarbar'));
			myChart.setOption(option);
			
		}
	});
}

function drawCourseBetweenRadar(activityId){
	if($('#group-version-Radarbar1').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-Radarbar1" style="height:400px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getCourseBetweenRadar?activityId='+activityId,
		success:function(data){

			var showLegendGroups=[];
			var showIndicatorGroupsData=[];
			var showDataGroupsScore=[];
			var max = 0
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){
					showLegendGroups.push(data.data[i].groupName);
				}
			}
			if(data.data.length>0){
				for(var i=0;i<data.data.length;i++){
					var temp={};
					var score=[];
					if(data.question.length>0){
						for(var j=0;j<data.question.length;j++){
							if(max<data.data[i].groupScore[data.question[j]]){
								max = Number(data.data[i].groupScore[data.question[j]]).toFixed(2);
							}
							score.push(Number(data.data[i].groupScore[data.question[j]]).toFixed(2));
						}
					}
					temp.name=data.data[i].groupName;
					temp.value=score;
					showDataGroupsScore.push(temp);
				}
			}
			if(data.question.length>0){
				for(var i=0;i<data.question.length;i++){
					var temp={};
					if(i==0){
						var showinfo={};
						var textStyle={};
						showinfo.show=true;
						showinfo.formatter=function(value,index){return value.toFixed(2)};
						textStyle.fontSize=10;
						textStyle.color='#333';
						showinfo.textStyle=textStyle;
						temp.axisLabel=showinfo;
					}
					temp.text=data.question[i];
					temp.max=max;
					showIndicatorGroupsData.push(temp);
				}
			}

			option = {
					title: {
					      text: '班级互评情况分析'
					},
					tooltip: {
						trigger: 'axis'
					},
				    legend: {
				    	top:[20],
				        data: showLegendGroups
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: showIndicatorGroupsData,
				        radius:120  
				    },
				    series: [{
				        tooltip: {
			                trigger: 'item'
			            },
			            type: 'radar',
				        // areaStyle: {normal: {}},
				        data : showDataGroupsScore
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-version-Radarbar1'));
			myChart.setOption(option);
			
		}
	});
}
function drawBetweenRelationship(activityId){// 画组间社交网络图的方法
	if($('#group-version-relationship2').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-relationship2" style="height:500px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getBetweenRelationship?activityId='+activityId,
		success:function(data){

			var pointsLink=[];// 该数据用于显示连接
			var pointsData=[];// 该数据用于存放社会网络图的人的节点

			var scoreArray=[];
			var scoreTemp;
			for(var u=0;u<data.data.length;u++){
				dataTemp=data.data[u];
				for(var i=0;i<dataTemp.groupUsersList.length;i++){
					var temp={};
					var item={};
					var normal={};
					normal.color ='#AE0000'
					item.normal=normal;
					temp.itemStyle=item;
					temp.name=dataTemp.groupUsersList[i];
					temp.x=Math.floor(Math.random()*1000+1);
					temp.y=Math.floor(Math.random()*200+1);
					temp.draggable = true;
					pointsData.push(temp);
				}
				for(var i=0;i<dataTemp.addCommentList.length;i++){
					if(dataTemp.addCommentList[i].length!=null){
						for(var j=0;j<dataTemp.addCommentList[i].length;j++){
							if(dataTemp.addCommentList[i][j].author!=dataTemp.addCommentList[i][j].commenter){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.addCommentList[i][j].author;
								temp.target=dataTemp.addCommentList[i][j].commenter;
								temp.name="addComment "+dataTemp.addCommentList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params, ticket, callback){
										var returnInfo =[];
										returnInfo = params.data.name.split(" ")
										return " C:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
				for(var i=0;i<dataTemp.replyList.length;i++){
					if(dataTemp.replyList[i].length!=null){
						for(var j=0;j<dataTemp.replyList[i].length;j++){
							if(dataTemp.replyList[i][j].Replyer!=dataTemp.replyList[i][j].author){
								var hasOne = false;
								for(var k=0;k<pointsLink.length;k++){
									if(pointsLink[k].source==dataTemp.replyList[i][j].Replyer&&pointsLink[k].target==dataTemp.replyList[i][j].author){
										hasOne = true; 
										pointsLink[k].name+=" Reply "+dataTemp.replyList[i][j].times;
										pointsLink[k].label.normal.formatter=function(params,ticket,callback){
											var returnInfo = params.data.name.split(" ");
											return " C:"+returnInfo[1]+" R:"+returnInfo[3];
										};
									}
								}
								if(hasOne == false){
									var temp={};
									var sTemp={};
									var lTemp={};
									var normalTemp={};
									temp.source=dataTemp.replyList[i][j].Replyer;
									temp.target=dataTemp.replyList[i][j].author;
									temp.name="Reply "+dataTemp.replyList[i][j].times;
									sTemp.trigger='item';
									sTemp.formatter=function(params,ticket,callback){
										return params.data.name;
										};
									normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " R:"+ returnInfo[1];
									};
									lTemp.show=true;
									lTemp.normal=normalTemp;
									temp.label=lTemp;
									temp.tooltip=sTemp;
									pointsLink.push(temp);
								}
							}
						}
					}
				}
				for(var i=0;i<dataTemp.gradeList.length;i++){
					if(dataTemp.gradeList[i].length!=null){
						for(var j=0;j<dataTemp.gradeList[i].length;j++){
							var hasOne = false;
							for(var k=0;k<pointsLink.length;k++){
								if(dataTemp.gradeList[i][j].grader==pointsLink[k].source&&dataTemp.gradeList[i][j].author==pointsLink[k].target){
									hasOne = true;
									pointsLink[k].name+=" Grade "+dataTemp.gradeList[i][j].times;
									pointsLink[k].label.normal.formatter=function(params,ticket,callback){
										var listTemp = params.data.name.split(" ");
										var returnTemp = null;

										if(listTemp.length>5){
											returnTemp=" C:"+listTemp[1]+" R:"+listTemp[3]+" G:"+listTemp[5];
										}
										else{
											if(listTemp[0]=="addComment"){
												returnTemp=" C:"+listTemp[1]+" G:"+listTemp[3];
											}
											else if(listTemp[0]=="Reply"){
												returnTemp=" R:"+listTemp[1]+" G:"+listTemp[3];
											}
										}
										return returnTemp;
									};
								}
							}
							if(hasOne == false){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.gradeList[i][j].grader;
								temp.target=dataTemp.gradeList[i][j].author;
								temp.name="Grade "+dataTemp.gradeList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " G:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
			}

			for(var i=0;i<pointsLink.length;i++){
				var temp0 = {};
				var source = pointsLink[i].source;
				var name = pointsLink[i].name;
				var scoreList = name.split(" ");
				var score=0;
				var hasOne=false;
				if(scoreList.length>5){
					score = Number(scoreList[1])+Number(scoreList[3])+Number(scoreList[5]);
				}
				else if(scoreList.length>3){
					score = Number(scoreList[1])+Number(scoreList[3]);
				}
				else{
					score = Number(scoreList[1]);
				}
				for(var j=0;j<scoreArray.length;j++){
					if(scoreArray[j].source==source){
						hasOne=true;
						scoreArray[j].score+=score;
					}
				}
				if(hasOne==false){
					temp0.source= source;
					temp0.score = score;
					scoreArray.push(temp0);
				}
			}
			if(scoreArray.length>1){
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<scoreArray.length;j++){
						if(Number(scoreArray[i].score)>Number(scoreArray[j].score)){
							var scoreTemp = scoreArray[i];
							scoreArray[i]=scoreArray[j]
							scoreArray[j]=scoreTemp;
						}
					}
				}
			}
			if(scoreArray.length>=3){
				var colorTemp = parseInt(scoreArray.length/3);
			}
			else{
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#0072E3';
						}
					}
				}
			}

			for(var i=0;i<2*colorTemp;i++){
				if(i<colorTemp){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#07ac72';
						}
					}
				}
				else if(i<(2*colorTemp)){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#f90';
						}
					}
				}
			}
			option = {
				    title: {
				        text: '班级交互分析',
				        x:'center'
				    },
				    tooltip:{
						trigger:'axis'
					},
					animationDurationUpdate:1500,
					animationEasingUpdate:'quinticInOut',
				    series : [
				        {
				            type: 'graph',
				            layout: 'force',
				            symbolSize: 50,
				            roam: true,
				            force: {
			                    repulsion: 5000
			                },
				            tooltip:{
				            	trigger:'item'
				            },
				            label: {
				                normal: {
				                    show: true
				                }
				            },
				            edgeSymbol: ['circle', 'arrow'],
				            edgeSymbolSize: [4, 8],
				            edgeLabel: {
				                normal: {
				                	show:true,
				                    textStyle: {
				                        fontSize: 15
				                    }
				                }
				            },
				            lineStyle:{
				            	normal:{
				            		opacity:1,
				            		width:2,
				            		curveness:0.1
				            	}
				            },
				            data: pointsData,
				            // links: [],
				            links: pointsLink
				        }
				    ]
				};
			var myChart = echarts.init(document.getElementById('group-version-relationship2'));
			myChart.setOption(option);
		}
	});
}
function drawRelationshipB(activityId){// 画组间社交网络图的方法
	if($('#group-version-relationship2').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-relationship_courseB" style="height:500px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getBetweenRelationship?activityId='+activityId,
		success:function(data){

			var pointsLink=[];// 该数据用于显示连接
			var pointsData=[];// 该数据用于存放社会网络图的人的节点

			var scoreArray=[];
			var scoreTemp;
			for(var u=0;u<data.data.length;u++){
				dataTemp=data.data[u];
				for(var i=0;i<dataTemp.groupUsersList.length;i++){
					var temp={};
					var item={};
					var normal={};
					normal.color ='#AE0000'
					item.normal=normal;
					temp.itemStyle=item;
					temp.name=dataTemp.groupUsersList[i];
					temp.x=Math.floor(Math.random()*1000+1);
					temp.y=Math.floor(Math.random()*200+1);
					temp.draggable = true;
					pointsData.push(temp);
				}
				for(var i=0;i<dataTemp.addCommentList.length;i++){
					if(dataTemp.addCommentList[i].length!=null){
						for(var j=0;j<dataTemp.addCommentList[i].length;j++){
							if(dataTemp.addCommentList[i][j].author!=dataTemp.addCommentList[i][j].commenter){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.addCommentList[i][j].author;
								temp.target=dataTemp.addCommentList[i][j].commenter;
								temp.name="addComment "+dataTemp.addCommentList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params, ticket, callback){
										var returnInfo =[];
										returnInfo = params.data.name.split(" ")
										return " C:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
				for(var i=0;i<dataTemp.replyList.length;i++){
					if(dataTemp.replyList[i].length!=null){
						for(var j=0;j<dataTemp.replyList[i].length;j++){
							if(dataTemp.replyList[i][j].Replyer!=dataTemp.replyList[i][j].author){
								var hasOne = false;
								for(var k=0;k<pointsLink.length;k++){
									if(pointsLink[k].source==dataTemp.replyList[i][j].Replyer&&pointsLink[k].target==dataTemp.replyList[i][j].author){
										hasOne = true; 
										pointsLink[k].name+=" Reply "+dataTemp.replyList[i][j].times;
										pointsLink[k].label.normal.formatter=function(params,ticket,callback){
											var returnInfo = params.data.name.split(" ");
											return " C:"+returnInfo[1]+" R:"+returnInfo[3];
										};
									}
								}
								if(hasOne == false){
									var temp={};
									var sTemp={};
									var lTemp={};
									var normalTemp={};
									temp.source=dataTemp.replyList[i][j].Replyer;
									temp.target=dataTemp.replyList[i][j].author;
									temp.name="Reply "+dataTemp.replyList[i][j].times;
									sTemp.trigger='item';
									sTemp.formatter=function(params,ticket,callback){
										return params.data.name;
										};
									normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " R:"+ returnInfo[1];
									};
									lTemp.show=true;
									lTemp.normal=normalTemp;
									temp.label=lTemp;
									temp.tooltip=sTemp;
									pointsLink.push(temp);
								}
							}
						}
					}
				}
				for(var i=0;i<dataTemp.gradeList.length;i++){
					if(dataTemp.gradeList[i].length!=null){
						for(var j=0;j<dataTemp.gradeList[i].length;j++){
							var hasOne = false;
							for(var k=0;k<pointsLink.length;k++){
								if(dataTemp.gradeList[i][j].grader==pointsLink[k].source&&dataTemp.gradeList[i][j].author==pointsLink[k].target){
									hasOne = true;
									pointsLink[k].name+=" Grade "+dataTemp.gradeList[i][j].times;
									pointsLink[k].label.normal.formatter=function(params,ticket,callback){
										var listTemp = params.data.name.split(" ");
										var returnTemp = null;

										if(listTemp.length>5){
											returnTemp=" C:"+listTemp[1]+" R:"+listTemp[3]+" G:"+listTemp[5];
										}
										else{
											if(listTemp[0]=="addComment"){
												returnTemp=" C:"+listTemp[1]+" G:"+listTemp[3];
											}
											else if(listTemp[0]=="Reply"){
												returnTemp=" R:"+listTemp[1]+" G:"+listTemp[3];
											}
										}
										return returnTemp;
									};
								}
							}
							if(hasOne == false){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.gradeList[i][j].grader;
								temp.target=dataTemp.gradeList[i][j].author;
								temp.name="Grade "+dataTemp.gradeList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " G:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
			}

			for(var i=0;i<pointsLink.length;i++){
				var temp0 = {};
				var source = pointsLink[i].source;
				var name = pointsLink[i].name;
				var scoreList = name.split(" ");
				var score=0;
				var hasOne=false;
				if(scoreList.length>5){
					score = Number(scoreList[1])+Number(scoreList[3])+Number(scoreList[5]);
				}
				else if(scoreList.length>3){
					score = Number(scoreList[1])+Number(scoreList[3]);
				}
				else{
					score = Number(scoreList[1]);
				}
				for(var j=0;j<scoreArray.length;j++){
					if(scoreArray[j].source==source){
						hasOne=true;
						scoreArray[j].score+=score;
					}
				}
				if(hasOne==false){
					temp0.source= source;
					temp0.score = score;
					scoreArray.push(temp0);
				}
			}
			if(scoreArray.length>1){
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<scoreArray.length;j++){
						if(Number(scoreArray[i].score)>Number(scoreArray[j].score)){
							var scoreTemp = scoreArray[i];
							scoreArray[i]=scoreArray[j]
							scoreArray[j]=scoreTemp;
						}
					}
				}
			}
			if(scoreArray.length>=3){
				var colorTemp = parseInt(scoreArray.length/3);
			}
			else{
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#0072E3';
						}
					}
				}
			}

			for(var i=0;i<2*colorTemp;i++){
				if(i<colorTemp){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#07ac72';
						}
					}
				}
				else if(i<(2*colorTemp)){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#f90';
						}
					}
				}
			}
			option = {
				    title: {
				        text: '班级交互分析',
				        x:'center'
				    },
				    tooltip:{
						trigger:'axis'
					},
					animationDurationUpdate:1500,
					animationEasingUpdate:'quinticInOut',
				    series : [
				        {
				            type: 'graph',
				            layout: 'force',
				            symbolSize: 50,
				            roam: true,
				            force: {
			                    repulsion: 5000
			                },
				            tooltip:{
				            	trigger:'item'
				            },
				            label: {
				                normal: {
				                    show: true
				                }
				            },
				            edgeSymbol: ['circle', 'arrow'],
				            edgeSymbolSize: [4, 8],
				            edgeLabel: {
				                normal: {
				                	show:true,
				                    textStyle: {
				                        fontSize: 15
				                    }
				                }
				            },
				            lineStyle:{
				            	normal:{
				            		opacity:1,
				            		width:2,
				            		curveness:0.1
				            	}
				            },
				            data: pointsData,
				            // links: [],
				            links: pointsLink
				        }
				    ]
				};
			var myChart = echarts.init(document.getElementById('group-version-relationship_courseB'));
			myChart.setOption(option);
		}
	});
}
function drawCrouseBetweenRalationship(activityId){
	if($('#group-version-relationship_course').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-relationship_course" style="height:500px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getBetweenRelationshipB?activityId='+activityId,
		success:function(data){

			var pointsLink=[];// 该数据用于显示连接
			var pointsData=[];// 该数据用于存放社会网络图的人的节点

			var scoreArray=[];
			var scoreTemp;
			for(var u=0;u<data.data.length;u++){
				dataTemp=data.data[u];
				for(var i=0;i<dataTemp.groupUsersList.length;i++){
					var temp={};
					var item={};
					var normal={};
					normal.color ='#AE0000'
					item.normal=normal;
					temp.itemStyle=item;
					temp.name=dataTemp.groupUsersList[i];
					temp.x=Math.floor(Math.random()*1000+1);
					temp.y=Math.floor(Math.random()*200+1);
					temp.draggable = true;
					pointsData.push(temp);
				}
				for(var i=0;i<dataTemp.addCommentList.length;i++){
					if(dataTemp.addCommentList[i].length!=null){
						for(var j=0;j<dataTemp.addCommentList[i].length;j++){
							if(dataTemp.addCommentList[i][j].author!=dataTemp.addCommentList[i][j].commenter){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.addCommentList[i][j].author;
								temp.target=dataTemp.addCommentList[i][j].commenter;
								temp.name="addComment "+dataTemp.addCommentList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params, ticket, callback){
										var returnInfo =[];
										returnInfo = params.data.name.split(" ")
										return " C:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
				for(var i=0;i<dataTemp.replyList.length;i++){
					if(dataTemp.replyList[i].length!=null){
						for(var j=0;j<dataTemp.replyList[i].length;j++){
							if(dataTemp.replyList[i][j].Replyer!=dataTemp.replyList[i][j].author){
								var hasOne = false;
								for(var k=0;k<pointsLink.length;k++){
									if(pointsLink[k].source==dataTemp.replyList[i][j].Replyer&&pointsLink[k].target==dataTemp.replyList[i][j].author){
										hasOne = true; 
										pointsLink[k].name+=" Reply "+dataTemp.replyList[i][j].times;
										pointsLink[k].label.normal.formatter=function(params,ticket,callback){
											var returnInfo = params.data.name.split(" ");
											return " C:"+returnInfo[1]+" R:"+returnInfo[3];
										};
									}
								}
								if(hasOne == false){
									var temp={};
									var sTemp={};
									var lTemp={};
									var normalTemp={};
									temp.source=dataTemp.replyList[i][j].Replyer;
									temp.target=dataTemp.replyList[i][j].author;
									temp.name="Reply "+dataTemp.replyList[i][j].times;
									sTemp.trigger='item';
									sTemp.formatter=function(params,ticket,callback){
										return params.data.name;
										};
									normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " R:"+ returnInfo[1];
									};
									lTemp.show=true;
									lTemp.normal=normalTemp;
									temp.label=lTemp;
									temp.tooltip=sTemp;
									pointsLink.push(temp);
								}
							}
						}
					}
				}
				for(var i=0;i<dataTemp.gradeList.length;i++){
					if(dataTemp.gradeList[i].length!=null){
						for(var j=0;j<dataTemp.gradeList[i].length;j++){
							var hasOne = false;
							for(var k=0;k<pointsLink.length;k++){
								if(dataTemp.gradeList[i][j].grader==pointsLink[k].source&&dataTemp.gradeList[i][j].author==pointsLink[k].target){
									hasOne = true;
									pointsLink[k].name+=" Grade "+dataTemp.gradeList[i][j].times;
									pointsLink[k].label.normal.formatter=function(params,ticket,callback){
										var listTemp = params.data.name.split(" ");
										var returnTemp = null;

										if(listTemp.length>5){
											returnTemp=" C:"+listTemp[1]+" R:"+listTemp[3]+" G:"+listTemp[5];
										}
										else{
											if(listTemp[0]=="addComment"){
												returnTemp=" C:"+listTemp[1]+" G:"+listTemp[3];
											}
											else if(listTemp[0]=="Reply"){
												returnTemp=" R:"+listTemp[1]+" G:"+listTemp[3];
											}
										}
										return returnTemp;
									};
								}
							}
							if(hasOne == false){
								var temp={};
								var sTemp={};
								var lTemp={};
								var normalTemp={};
								temp.source=dataTemp.gradeList[i][j].grader;
								temp.target=dataTemp.gradeList[i][j].author;
								temp.name="Grade "+dataTemp.gradeList[i][j].times;
								sTemp.trigger='item';
								sTemp.formatter=function(params,ticket,callback){
									return params.data.name;
									};
								lTemp.show=true;
								normalTemp.formatter=function(params,ticket,callback){
										var returnInfo = params.data.name.split(" ");
										return " G:"+returnInfo[1];
									};
								lTemp.normal=normalTemp;
								temp.label=lTemp;
								temp.tooltip=sTemp;
								pointsLink.push(temp);
							}
						}
					}
				}
			}

			for(var i=0;i<pointsLink.length;i++){
				var temp0 = {};
				var source = pointsLink[i].source;
				var name = pointsLink[i].name;
				var scoreList = name.split(" ");
				var score=0;
				var hasOne=false;
				if(scoreList.length>5){
					score = Number(scoreList[1])+Number(scoreList[3])+Number(scoreList[5]);
				}
				else if(scoreList.length>3){
					score = Number(scoreList[1])+Number(scoreList[3]);
				}
				else{
					score = Number(scoreList[1]);
				}
				for(var j=0;j<scoreArray.length;j++){
					if(scoreArray[j].source==source){
						hasOne=true;
						scoreArray[j].score+=score;
					}
				}
				if(hasOne==false){
					temp0.source= source;
					temp0.score = score;
					scoreArray.push(temp0);
				}
			}
			if(scoreArray.length>1){
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<scoreArray.length;j++){
						if(Number(scoreArray[i].score)>Number(scoreArray[j].score)){
							var scoreTemp = scoreArray[i];
							scoreArray[i]=scoreArray[j]
							scoreArray[j]=scoreTemp;
						}
					}
				}
			}
			if(scoreArray.length>=3){
				var colorTemp = parseInt(scoreArray.length/3);
			}
			else{
				for(var i=0;i<scoreArray.length;i++){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#0072E3';
						}
					}
				}
			}

			for(var i=0;i<2*colorTemp;i++){
				if(i<colorTemp){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#07ac72';
						}
					}
				}
				else if(i<(2*colorTemp)){
					for(var j=0;j<pointsData.length;j++){
						if(scoreArray[i].source==pointsData[j].name){
							pointsData[j].itemStyle.normal.color='#f90';
						}
					}
				}
			}
			option = {
				    title: {
				        text: '组内交互分析',
				        x:'center'
				    },
				    tooltip:{
						trigger:'axis'
					},
					animationDurationUpdate:1500,
					animationEasingUpdate:'quinticInOut',
				    series : [
				        {
				            type: 'graph',
				            layout: 'force',
				            symbolSize: 50,
				            roam: true,
				            force: {
			                    repulsion: 5000
			                },
				            tooltip:{
				            	trigger:'item'
				            },
				            label: {
				                normal: {
				                    show: true
				                }
				            },
				            edgeSymbol: ['circle', 'arrow'],
				            edgeSymbolSize: [4, 8],
				            edgeLabel: {
				                normal: {
				                	show:true,
				                    textStyle: {
				                        fontSize: 15
				                    }
				                }
				            },
				            lineStyle:{
				            	normal:{
				            		opacity:1,
				            		width:2,
				            		curveness:0.1
				            	}
				            },
				            data: pointsData,
				            // links: [],
				            links: pointsLink
				        }
				    ]
				};
				var myChart = echarts.init(document.getElementById('group-version-relationship_course'));
				myChart.setOption(option);
		}
	});
}
$(function(){
    /**
	 * 时间对象的格式化;
	 */  
    Date.prototype.format = function(format) {  
        /*
		 * eg:format="yyyy-MM-dd hh:mm:ss";
		 */  
        var o = {  
            "M+" : this.getMonth() + 1, // month
            "d+" : this.getDate(), // day
            "h+" : this.getHours(), // hour
            "m+" : this.getMinutes(), // minute
            "s+" : this.getSeconds(), // second
            "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
            "S" : this.getMilliseconds()  
            // millisecond
        }  
      
        if (/(y+)/.test(format)) {  
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
        }  
        for (var k in o) {  
            if (new RegExp("(" + k + ")").test(format)) {  
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
            }  
        }  
        return format;  
    }  
});
